package limitStream;

import java.util.stream.Stream;

public class LimitDemo02 {
    public static void main(String[] args) {
        //interage迭代器会一直进行下去，所以由inerate创建的流是无限流，需要limit方法截断
        Stream<Integer> demo03 = Stream.iterate(0, n -> n+2).limit(6);
        demo03.forEach(System.out::println);
        System.out.println("limit起到了什么作用呢？起到了截断的作用");
        Stream<Integer>  demo04 = Stream.iterate(0,n -> n+2).limit(7);
        demo04.forEach(System.out::println);
        System.out.println("generate方法");
        //generate方法
        Stream<Double> generateStream = Stream.generate(Math::random).limit(5);
        generateStream.forEach(System.out::println);
    }
}
